from MySQLPool import *

table_name="WECHAT_USER"
column_name_list="ID,SYS_USER_ID,WECHAT_NUMBER,WECHAT_NAME,WECHAT_CREDENTIAL,CREATE_USER,CREATE_TIME,UPDATE_USER,UPDATE_TIME,LOGIC_DEL_FLAG"

def queryByWechatName(wechatName):
    if wechatName is not None:
        with dbpool.get_connection() as connection:
            wechatUser=connection.query("select * from {table_name} where logic_del_flag=0 and wechat_name = %(wechatName)s",{"wechatName":wechatName})
            if wechatUser is None:
                return None
            else:
                return wechatUser
    return None


def insert(wechatUser):
    rows_affected=0
    if wechatUser is not None:
        with dbpool.get_connection() as connection:
            insert_query = "insert into {table_name} ({column_name_list}) values (null,%(SYS_USER_ID)s,%(WECHAT_NUMBER)s,%(WECHAT_NAME)s,%(WECHAT_CREDENTIAL)s,%(CREATE_USER)s,%(CREATE_TIME)s,%(UPDATE_USER)s,%(UPDATE_TIME)s,0)"
            rows_affected = connection.execute(insert_query, wechatUser)

    return rows_affected